package org.br.erp.rfq.xbj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.br.erp.rfq.xbj.entity.Scmxjditem;
import org.br.erp.rfq.xbj.mapper.ScmxjditemMapper;
import org.br.erp.rfq.xbj.service.IScmxjditemService;
import org.br.erp.rfq.xbj.vo.ScmXjdItemVo;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.DictModel;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 询价单分录
 * @Author: jeecg-boot
 * @Date:   2023-09-16
 * @Version: V1.0
 */
@Service
public class ScmxjditemServiceImpl extends ServiceImpl<ScmxjditemMapper, Scmxjditem> implements IScmxjditemService {
	
	@Autowired
	private ScmxjditemMapper scmxjditemMapper;

	@Autowired
	ISysBaseAPI sysBaseAPI;
	
	@Override
	public List<Scmxjditem> selectByMainId(String mainId) {
		return scmxjditemMapper.selectByMainId(mainId);
	}

	@Override
	public List<ScmXjdItemVo> getXjdItemVo(IPage<ScmXjdItemVo> page, QueryWrapper<ScmXjdItemVo> queryWrapper) {
		queryWrapper.eq("item.quoflag","1");
		queryWrapper.exists("select 1 from scmquotation where fromitemid = item.id");
		queryWrapper.eq("item.poflag","0");
		List<ScmXjdItemVo> xjdItemList = scmxjditemMapper.getXjdItemList(page, queryWrapper);
		List<DictModel> pjpz = sysBaseAPI.getDictItems("pjpz");
		for (ScmXjdItemVo scmXjdItemVo : xjdItemList) {
			String quality = scmXjdItemVo.getQuality();
			String qualityName = "";
			if(quality!=null && !quality.equalsIgnoreCase("")){
				String[] split = quality.split(",");
				for (String s : split) {
					for (DictModel dictModel : pjpz) {
						if(dictModel.getValue().equalsIgnoreCase(s)){
							qualityName+=dictModel.getText()+",";
							break;
						}
					}
				}
			}
			if(qualityName!=""){
				scmXjdItemVo.setQualityname(qualityName.substring(0,qualityName.length()-1));
			}
		}
		return xjdItemList;
	}
}
